package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
    private static DvdCollection collection;
    private static int dvdIDCount = 0;

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()//DVD container is to be passed as parameter from the main controller
    {
        collection = DvdCollection.getInstance();
    }
    
    /**
     * This method returns a DVD with the give id.
     * 
     * @param   id  The id of the dvd
     * 
     * @return      A DVD with the given id
     */
    public DVD findDVD(long id)
    {
       return collection.getDVD(id);
    }
    
    /**
     * This method returns a Copy with the given serial number, from  a DVD with the given id.
     * 
     * @param   id              The id of the DVD
     * @param   serialNumber    The serial number of the copy
     * 
     * @return  An object of tyoe Copy.
     */
    public Copy findCopy(long id,String serialNumber)
    {
        return collection.getCopy(id,serialNumber);
    }
    
    /**
     * This method creates a new object of the type DVD and associates it with the DVD container.
     * 
     * @param   id          The id of the dvd
     * @param   title       The title of the dvd
     * @param   director    The director of the dvd
     * @param   releaseDate The release date of the dvd
     */
    public void createDVD(String title, String director, String releaseDate)
    {
        dvdIDCount++;
        collection.createDvd(dvdIDCount, title, director, releaseDate);
    }
    
    /**
     * This method creates a new copy of an already existing dvd
     * 
     * @param   id                  The id of the dvd of witch the copy is to be created.
     * @param   serialNumber        The serial number of the copy
     * @param   acquisitionDate     The date of acquisition for the copy
     * @param   acquisitionPrice    The acquisition price of the copy
     */
    public void createCopy(long id, String serialNumber, String acquisitionDate, double acquisitionPrice)
    {
        collection.createCopy(id, serialNumber, acquisitionDate, acquisitionPrice);
    }
    
    /**
     * This method deletes a DVD from the container
     * 
     * @param   id  The id of the DVD to be deleted
     */
    public boolean deleteDVD(long id)
    {
        return collection.deleteDVD(id);
    }
    
    /**
     * This method delete of copy of DVD.
     * 
     * @param   id              the id of the dvd
     * @param   serialNumber    the serial number of the copy
     */
    public boolean deleteCopy(long id, String serialNumber)
    {
        return collection.deleteCopy(id, serialNumber);
    }
    
    /**
     * This method updates the information registered about a dvd.
     * 
     * @param   id          The id of the dvd
     * @param   title       The title of the dvd
     * @param   director    The director of the dvd
     * @param   releaseDate The release date of the dvd
     */
    public void updateDvd(long id, String title, String director, String releaseDate)
    {
        collection.updateDVD(id, title, director, releaseDate);
    }
    
    /**
     * This method returns a full list of all DVD's
     * 
     * @return  A list of DVD's, as an ArrayList<DVD>
     */
    public ArrayList listAllDvds()
    {
          return collection.listAllDvds();
    }
    
    /**
     * This method examines whether the dvd list is empty
     */
    public boolean isDvdListEmpty()
    {
        boolean a;
        if(listAllDvds().size()>0)
        {
            a = false;
        }
        else
        {
            a = true;
        }
        return a;
    }
    
    /**
     * This method determines wether a dvd obejct with id exists.
     * 
     * @param   id  The id of the dvd
     * @return  Weather the dvd exist, as a boolean.
     */
    public boolean hasDvd(long id)
    {
        return collection.hasDvd(id);
    }
}